package concurrentAPI;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ExecutorsAndThreadPoolsDemo {

	private static class Task implements Runnable {
		private int taskId;
		
		public Task(int taskId) {
			this.taskId = taskId;
		}

		public void run() {
			System.out.println("Task started: " + taskId);
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				return;
			}
			System.out.println("Task finished: " + taskId);
		}
	}
	
	public static void main(String[] args) {
		ExecutorService executor =
			Executors.newFixedThreadPool(50);
		
		for (int i=1; i<1000; i++) {
			Task task = new Task(i);
			executor.execute(task);
		}
		
		System.out.println("Tasks scheduled.");
	}

}
